import request from '@/utils/request'
/**
 *登录
 * @param {string} username 账号
 * @param {string} password 密码
 * @returns Promise
 */
export const userLoginAPI = (username, password) => {
  return request({
    url: '/user/login',
    method: 'POST',
    data: {
      username,
      password
    }
  })
}
/**
 *注册账号
 * @param {string} username 账号
 * @param {string} password 密码
 * @returns Promise
 */
export const userRegisteredAPI = (username, password) => {
  return request({
    url: '/user/registered',
    method: 'POST',
    data: {
      username,
      password
    }
  })
}
/**
 *获取用户个人信息
 * @returns Promise
 */
export const userAPI = () => {
  return request({
    url: '/user'
  })
}
/**
 *退出登录
 * @returns Promise
 */
export const userLogoutAPI = () => {
  return request({
    url: '/user/logout',
    method: 'POST'
  })
}
/**
 * 查看收藏列表
 * @returns Promise
 */
export const userFavoritesAPI = () => {
  return request({
    url: '/user/favorites'
  })
}
/**
 * 查看已发布房源列表
 * @returns Promise
 */
export const userGetHousesAPI = () => {
  return request({
    url: '/user/houses'
  })
}
/**
 * 更新用户数据
 * @param {*} avatar 姓名
 * @param {*} gender 性别
 * @param {*} nickname 昵称
 * @param {*} phone 手机号
 * @returns Promise
 */
export const userUpdateAPI = (avatar, gender, nickname, phone) => {
  return request({
    url: '/user',
    method: 'PATCH',
    data: {
      avatar,
      gender,
      nickname,
      phone
    }
  })
}
/**
 * 房屋是否收藏
 * @param {string|number} id 房屋的code值
 * @returns Promise
 */
export const getUserFavoritesIdAPI = (id) => {
  return request({
    url: `/user/favorites/${id}`
  })
}
/**
 * 添加收藏
 * @param {string|number} id 房屋的code值
 * @returns Promise
 */
export const postUserFavoritesIdAPI = (id) => {
  return request({
    url: `/user/favorites/${id}`,
    method: 'POST'
  })
}
/**
 * 删除收藏
 * @param {string|number} id 房屋的code值
 * @returns Promise
 */
export const deleteUserFavoritesIdAPI = (id) => {
  return request({
    url: `/user/favorites/${id}`,
    method: 'DELETE'
  })
}
/**
 * 发布房源
 * @param {object} data 房屋信息{
 * "title": "整租 · 豪华小区 精装修出租 小区环境幽静",
 * "description": "【装修描述】 装修简洁，家电配齐，通风采光效果良好，格局方正。",
 * "houseImg": "img1|im2|img3",
 * "oriented": "ORIEN|caa6f80b-b764-c2df",
 * "supporting": "空调|洗衣机",
 * "price": "1234",
 * "roomType": "ROOM|ce2a5daa-811d-2f49",
 * "size": "123",
 * "floor": "FLOOR|1",
 * "community": "AREA|93cbbe43-741d-de54"
 *  }
 * @returns Promise
 */
export const userPostHousesAPI = (data) => {
  return request({
    url: '/user/houses',
    method: 'POST',
    data
  })
}
/**
 * 上下架房屋
 * @param {string|number} id 用户房屋的code
 * @param {boolean} shelf 用户房屋上下架
 * @returns  Promise
 */
export const userHousesIdAPI = (id, shelf) => {
  return request({
    url: `/user/houses/${id}`,
    method: 'PATCH',
    data: {
      shelf
    }
  })
}
